//**************************************************************************************************************
// CLASS: Integer
//
// DESCRIPTION
// See comments in Integer.hpp.
//
// AUTHOR INFORMATION
// Group 2
// Tyler Williams
// Lauren Walker
// Cameron Stewart
// Fatimah Alowah
//**************************************************************************************************************
#include <cstdlib>      // For atoi() function.
#include <sstream>      // For stringstream class.
#include "Integer.hpp"

//==============================================================================================================
// PUBLIC FUNCTIONS
//==============================================================================================================

//--------------------------------------------------------------------------------------------------------------
// Default ctor.
//
// DESCRIPTION:
// Calls the base class Operand::Operand(string const&) ctor. Then converts pValue into an actual int and stores
// the converted int into the mInt data member.
// IMPORTANT:
// To convert the string representations of an integer into an actual int, call the C Standard Library function
// atoi() [alpha to int]. Note that atoi() expects a C string as the parameter, but pValue is a C++ std::string.
// The C++ std::string class simply encapsulates a C string, so to get the C string (really a pointer to the
// C string) encapsulated within a std::string object, call the std::string::c_str() function.
//--------------------------------------------------------------------------------------------------------------
Integer::Integer
(
 std::string const& pValue
 )
:
Operand(pValue),
mInt(atoi(pValue.c_str()))
{
}

//--------------------------------------------------------------------------------------------------------------
// Copy ctor.
//--------------------------------------------------------------------------------------------------------------
Integer::Integer
(
 Integer const& pInteger
 )

{
    Copy(pInteger);
}

//--------------------------------------------------------------------------------------------------------------
// Dtor.
//--------------------------------------------------------------------------------------------------------------
Integer::~Integer
(
)
{
}

//--------------------------------------------------------------------------------------------------------------
// GetValue()
//
// DESCRIPTION:
// mInt accessor function.
//--------------------------------------------------------------------------------------------------------------
int32 Integer::GetValue
(
)
const
{
    return mInt;
}

//--------------------------------------------------------------------------------------------------------------
// operator=()
//-------------------------------------------------------------------------------------------------------------
Integer& Integer::operator=
(
 Integer const& pInteger
 )
{
    if (this != &pInteger) Copy(pInteger);
    return *this;
}

//--------------------------------------------------------------------------------------------------------------
// SetValue()
//
// DESCRIPTION:
// mInt mutator function.
//--------------------------------------------------------------------------------------------------------------
void Integer::SetValue
(
 int32 const pValue
 )
{
    mInt = pValue;
}

//==============================================================================================================
// PROTECTED FUNCTION MEMBERS
//==============================================================================================================

//--------------------------------------------------------------------------------------------------------------
// Copy()
//
// DESCRIPTION:
// Makes 'this' Integer a copy of pInteger.
//--------------------------------------------------------------------------------------------------------------
void Integer::Copy
(
 Integer const& pInteger
 )
{
    // Copy the base class (Operand) data members to 'this'.
    Operand::Copy(pInteger);
    
    // Copy the derived class (Label) data members to 'this;.
    SetValue(pInteger.GetValue());
}

//==============================================================================================================
// PRIVATE FUNCTION MEMBERS
//==============================================================================================================

